package com.ship.dispatch.bean.orderPay;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ship.common.core.base.ContractBaseBean;
import com.ship.common.core.base.Joinable;
import com.ship.common.core.mapping.Label;
import com.ship.common.core.mapping.SearchItem;
import com.ship.common.core.mapping.TableColumn;
import com.ship.common.core.validate.Add;
import com.ship.common.core.validate.Update;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @author 31463
 */
@TableName("con_insurance_people")
@Data
public class ConInsurancePeople extends ContractBaseBean implements Joinable {

    private static final long serialVersionUID = -2009723224391298906L;
    /**
     *合同名称
     */
    @Label(value="合同名称")
    @TableColumn
    private String contractName;

    /**
     *合同编号
     */
    @Label(value="合同编号")
    @TableColumn
    private String contractNumber;

    /**
     *贸易主体(国贸、新贸)
     */
    @Label(value="贸易主体",enumContent = "贸易主体",multiSelect = true)
    @SearchItem
    @TableColumn
    @NotNull(message = "贸易主体不能为空", groups = {Update.class})
    private Integer tradeBody;

    @TableField(exist = false)
    private String tradeBodyListForSearch;

    /**
     *签订日期
     */
    @Label(value="签订日期")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @SearchItem
    @TableColumn
    @NotNull(message = "签订日期不能为空", groups = {Update.class})
    private Date signingDate;

    /**
     *被保险人
     */
    @Label(value="被保险人")
    @TableColumn
    @NotBlank(message = "被保险人不能为空", groups = {Update.class, Add.class})
    @Size(max = 255, message = "被保险人长度不能超过255", groups = {Update.class, Add.class})
    private String assured;

    /**
     *承保人
     */
    @NotBlank(message = "承保人不能为空", groups = {Update.class, Add.class})
    @Size(max = 255, message = "承保人长度不能超过255", groups = {Update.class, Add.class})
    @Label(value="承保人")
    @SearchItem
    @TableColumn
    private String insurer;

    /**
     *价格
     */
    @Label(value="价格")
    @NotNull(message = "价格不能为空", groups = {Add.class})
    private BigDecimal price;

    /**
     *价格
     */
    @Label(value="价格")
    @TableField(exist = false)
    @TableColumn
    private String priceStr;

    /**
     *币种
     */
    @Label(value="币种",enumContent = "币种")
    private Integer currency;

    /**
     *服务期限(单位年)
     */
    @Label(value="服务期限")
    @NotNull(message = "服务期限不能为空", groups = {Add.class})
    private Integer servicePeriod;

    /**
     *服务期限单位-年
     */
    @Label(value="服务期限")
    @TableField(exist = false)
    @TableColumn
    private String servicePeriodStr;

    /**
     *到期时间
     */
    @Label(value="到期时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @TableColumn
    @NotNull(message = "到期时间不能为空", groups = {Add.class})
    private Date expirationDate;

    /**
     *删除申请
     */
    @Label(value="删除申请",boolContent = true)
    private Boolean delApply;

    /**
     *合同状态
     */
    @Label(value="合同状态",enumContent = "合同状态")
    private Integer status;

    /**
     *是否是优秀案例
     */
    @Label(value="优秀案例",enumContent = "是否是优秀案例")
    private Integer excellent;

    /**
     * 附件地址
     */
    @TableField(exist = false)
    private String filePath;

    /**
     * 合同上传时间
     */
    @Label(value="合同上传时间")
    @TableColumn
    @TableField(fill = FieldFill.INSERT)
    private Date createDate;

    /**
     * 创建者
     */
    @Label(value="创建者")
    @SearchItem
    @TableColumn
    @TableField(fill = FieldFill.INSERT)
    private String createBy;

    public String getPriceStr(){
        String result = null;
        if (getPrice()!=null) {
            result = decimalFormat.format(getPrice());
            if (currency == 1) {
                result = "$" + result;
            }
            if (currency == 2) {
                result = "¥" + result;
            }
            if (currency == 3) {
                result = "€" + result;
            }
            if (currency == 4) {
                result = "￡" + result;
            }
            if (currency == 5) {
                result = "C$" + result;
            }
            if (currency == 6) {
                result = "￥" + result;
            }
            if (currency == 7) {
                result = "₹" + result;
            }
            if (currency == 8) {
                result = "p" + result;
            }
            if (currency == 9) {
                result = "₽" + result;
            }
        }
        return result;
    }

    public String getServicePeriodStr(){
        String result = null;
        if (getServicePeriod()!=null){
            result = getServicePeriod()+"年";}
        return result;
    }

    @Override
    public String getLabel() {
        return null;
    }

    @Override
    public String getValue() {
        return null;
    }
}
